package orgs.example.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import orgs.example.mapper.AdminMapper;
import orgs.example.mapper.CustomerMapper;
import orgs.example.mapper.StaffMapper;
import orgs.example.pojo.MeetingRoom;
import orgs.example.pojo.Reservation;
import orgs.example.pojo.User;
import orgs.example.service.AdminService;

import java.util.List;

@Service
public class AdminServiceImpl implements AdminService {

    @Autowired
    private AdminMapper adminMapper;

    @Autowired
    private CustomerMapper customerMapper;

    @Autowired
    private StaffMapper staffMapper;

    @Override
    public Boolean addMeetingRoom(MeetingRoom meetingRoom) {
        adminMapper.addMeetingRoom(meetingRoom);

        return true;
    }

    @Override
    public Boolean changeMeetingroom(MeetingRoom meetingRoom) {
        adminMapper.changeMeetingroom(meetingRoom);
        return true;
    }

    @Override
    public Boolean deleteroom(Integer roomid) {
        adminMapper.deleteroom(roomid);
        return true;
    }

    @Override
    public Boolean changeUserStatus(Integer userId, String userStatus) {
        adminMapper.changeUserStatus(userId,userStatus);
        return true;
    }

    @Override
    public Boolean deleteuser(Integer userId) {
        adminMapper.deleteuser(userId);
        return true;
    }

    @Override
    public List<User> searchUser(User user) {
        List<User> users = adminMapper.searchUser(user);
        return users;
    }

    @Override
    public List<MeetingRoom> searchMeetingRoom(MeetingRoom meetingRoom) {

        return adminMapper.searchMeetingRoom(meetingRoom);

    }

    @Override
    public MeetingRoom searchRoomByRoomId(Integer roomId) {

        MeetingRoom r =  customerMapper.searchRoomByRoomId(roomId);

        return r;
    }

    @Override
    public void deleteReservaionByUserId(Integer userId) {
        adminMapper.deleteReservaionByUserId(userId);
    }

    @Override
    public void deleteCancellationByuserId(Integer userId) {
        List<Reservation> reservations = customerMapper.searchReservationByUserId(userId);
        for (Reservation r : reservations){
            adminMapper.deleteCancellationByReserveId(r.getReserveId());
        }
    }

    @Override
    public void changeRoomStatus(Integer roomid, String status) {
        staffMapper.changeRoomStatus(roomid,status);
    }

    @Override
    public List<Reservation> searchAllReservation() {
        return staffMapper.searchAllReservation();
    }
}
